package com.example.reference_book.controller;

import com.example.reference_book.entity.Book;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("Context")
public class Context {
    @Resource
    private BookStrategy bookStrategy;
    public Context(){
        this.bookStrategy=null;
    }
    public void setBookStrategy(BookStrategy bookStrategy){
        this.bookStrategy=bookStrategy;
    }

    @GetMapping("/{type}/{key}")
    public List<Book> executeStrategy(String type, String key){
        return this.bookStrategy.searchByType(type, key);
    }
}
